package com.ssmsq.multidatabase.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ssmsq.multidatabase.entity.SysRole;
import com.ssmsq.multidatabase.entity.YwzxXiangmu;
import com.ssmsq.multidatabase.entity.SysUser;
import com.ssmsq.multidatabase.mapper.SysRoleMapper;
import com.ssmsq.multidatabase.mapper.SysUserMapper;
import com.ssmsq.multidatabase.mapper.YwzxXiangmuMapper;
import com.ssmsq.multidatabase.service.SsmService;
import com.ssmsq.multidatabase.service.SysRoleService;
import com.ssmsq.multidatabase.service.SysUserService;
import com.ssmsq.multidatabase.service.YwzxXiangmuService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author sss
 */
@RestController
@RequestMapping(value = "ssm")
public class SsmController {

    @Resource
    private SysUserMapper sysUserMapper;

    @Resource
    private YwzxXiangmuMapper ywzxXiangmuMapper;

    @Resource
    private SysRoleMapper sysRoleMapper;

    @Resource
    private SysUserService sysUserService;

    @Resource
    private YwzxXiangmuService ywzxXiangmuService;

    @Resource
    private SysRoleService sysRoleService;

    @Resource
    private SsmService ssmService;

    @RequestMapping("roll")
    public Object roll(@RequestParam(required = false) Integer a, @RequestParam(required = false) Integer b) {
        return ssmService.testRoll(a, b);
    }

    @RequestMapping("mongoSave")
    public Object mongoSave(@RequestParam(required = false) Integer a, @RequestParam(required = false) Integer b) {
        return ssmService.mongoSave(a, b);
    }

    @RequestMapping("mongoGet")
    public Object mongoGet(@RequestParam(required = false) Integer a, @RequestParam(required = false) Integer b) {
        return ssmService.mongoGet(a, b);
    }

    @RequestMapping("redisSave")
    public Object redisSave(@RequestParam(required = false) Integer a, @RequestParam(required = false) Integer b) {
        return ssmService.redisSave(a, b);
    }

    @RequestMapping("redisGet")
    public Object redisGet(@RequestParam(required = false) Integer a, @RequestParam(required = false) Integer b) {
        return ssmService.redisGet(a, b);
    }

    @RequestMapping("test3")
    public Map<String, Object> test3(@RequestParam(required = false) Integer type) {
        Map<String, Object> res = new HashMap<>();
        if (type == null || type == 1) {
            List<SysUser> list = sysUserService.list();
            res.put("user", list);
        } else if (type == 2) {
            List<YwzxXiangmu> list = ywzxXiangmuService.list();
            res.put("xiangmu", list);
        } else if (type == 3) {
            List<SysRole> list = sysRoleService.list();
            res.put("role", list);
        } else if (type == 4) {
            List<SysUser> list = sysUserMapper.selectList(null);
            res.put("role", list);
        } else if (type == 5) {
            List<YwzxXiangmu> list = ywzxXiangmuMapper.selectList(null);
            res.put("role", list);
        } else if (type == 6) {
            List<SysRole> list = sysRoleMapper.selectList(null);
            res.put("role", list);
        }
        return res;
    }

}
